from urllib import request, parse

url = 'https://www.runoob.com/try/py3/py3_urllib_test.php'  # 提交到表单页面
data = {'name': 'RUNOOB', 'tag': '菜鸟教程'}   # 提交数据
header = {
    'User-Agent':'Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
}   #头部信息

data = parse.urlencode(data).encode('utf-8')
req = request.Request(url, data, header)
rsp = request.urlopen(req).read()

fh = open("urllib_test_post_runoob.html", "wb")
fh.write(rsp)
fh.close()